package com.chats.pojo.vo;


import com.chats.pojo.Message;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 消息显示对象
 */
@Data
public class MessageVO {

    private Long id;

    @JsonSerialize(using = ToStringSerializer.class)
    private Long fromId; // 发送人id

    public String fromUsername; // 发送人用户名

    @JsonSerialize(using = ToStringSerializer.class)
    public Long toId; // 接收人id

    private String msg; // 内容

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime time; // 时间

    public MessageVO(Message message, String fromUsername) {
        this.id = message.getId();
        this.fromId = message.getFromId();
        this.msg = message.getMsg();
        this.time = message.getTime();
        this.fromUsername = fromUsername;
        this.toId = message.getToId();
    }


}
